#ifndef __HEROZ_SCREENS_HH__
#define __HEROZ_SCREENS_HH__
#include <SDL/SDL.h>
#include <vector>
#include <string>
#ifndef HeroZ
struct HeroZ;
#endif

#define SCREENWIDTH 40
#define SCREENHEIGHT 20
#define TILEWSHIFT 4
#define TILEHSHIFT 4
#define TILEWIDTH (1 << TILEWSHIFT)
#define TILEHEIGHT (1 << TILEHSHIFT)

struct Levels {
  struct Connection {
    short e, n, w, s;
    Connection();
  };
  typedef std::vector<Connection> ConnectionType;
  struct Level {
    short start; //!< Which screen should be the start screen?
    short player_x; //!< X-Position of player in start screen.
    short player_y; //!< Y-Position of player in start screen.
    ConnectionType conns;
  };
  typedef std::vector<Level> LevelType;
  
  LevelType levels;

  const Level &at(unsigned i) const { return levels.at(i); }
  void load(const char *fname);
};


struct ScreenCharacters {
  unsigned char s[SCREENHEIGHT][SCREENWIDTH + 1]; //The 41th Byte should be a LF...

  void set(unsigned int x, unsigned int y, char c);
  unsigned char get(unsigned int x, unsigned int y);
  unsigned char get_save(unsigned int x, unsigned int y, unsigned char c = ' ');
  void clear(unsigned char c = ' ');
  void shift_left();
  void shift_right();
  void shift_up();
  void shift_down();
};

std::vector<ScreenCharacters> load_screens(std::string path);
void save_screens(std::string path, const std::vector<ScreenCharacters> &screens);

std::vector<ScreenCharacters> &new_screen(std::vector<ScreenCharacters> &screens);

void copy_screen(int screen, HeroZ *heroz);

/*! \brief draw a character screen to a surface
 *
 * \param display Surface to draw on
 * \param gfxfont Surface with the tiles and the animation
 * \param asm animation sequence number
 * \param screen the screen to draw
 *
 */
void draw_screen(SDL_Surface *display, SDL_Surface *gfxfont, int asn, const ScreenCharacters *screen);

void draw_screen(HeroZ *heroz);

#endif
